home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / megazone.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  6KB  |  218 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. unsigned char *megazone_scrollx;
  13. unsigned char *megazone_scrolly;
  14. static int flipscreen;
  15.  
  16. unsigned char *megazone_videoram2;
  17. unsigned char *megazone_colorram2;
  18. size_t megazone_videoram2_size;
  19.  
  20. /***************************************************************************
  21.  
  22.   Convert the color PROMs into a more useable format.
  23.  
  24.   Megazone has one 32x8 palette PROM and two 256x4 lookup table PROMs
  25.   (one for characters, one for sprites).
  26.   The palette PROM is connected to the RGB output this way:
  27.  
  28.   bit 7 -- 220 ohm resistor  -- BLUE
  29.         -- 470 ohm resistor  -- BLUE
  30.         -- 220 ohm resistor  -- GREEN
  31.         -- 470 ohm resistor  -- GREEN
  32.         -- 1  kohm resistor  -- GREEN
  33.         -- 220 ohm resistor  -- RED
  34.         -- 470 ohm resistor  -- RED
  35.   bit 0 -- 1  kohm resistor  -- RED
  36.  
  37. ***************************************************************************/
  38. void megazone_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  39. {
  40.     int i;
  41.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  42.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  43.  
  44.  
  45.     for (i = 0;i < Machine->drv->total_colors;i++)
  46.     {
  47.         int bit0,bit1,bit2;
  48.  
  49.         /* red component */
  50.         bit0 = (*color_prom >> 0) & 0x01;
  51.         bit1 = (*color_prom >> 1) & 0x01;
  52.         bit2 = (*color_prom >> 2) & 0x01;
  53.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  54.         /* green component */
  55.         bit0 = (*color_prom >> 3) & 0x01;
  56.         bit1 = (*color_prom >> 4) & 0x01;
  57.         bit2 = (*color_prom >> 5) & 0x01;
  58.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  59.         /* blue component */
  60.         bit0 = 0;
  61.         bit1 = (*color_prom >> 6) & 0x01;
  62.         bit2 = (*color_prom >> 7) & 0x01;
  63.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  64.  
  65.         color_prom++;
  66.     }
  67.  
  68.     /* color_prom now points to the beginning of the lookup table */
  69.  
  70.     /* sprites */
  71.     for (i = 0;i < TOTAL_COLORS(1);i++)
  72.         COLOR(1,i) = *(color_prom++) & 0x0f;
  73.  
  74.     /* characters */
  75.     for (i = 0;i < TOTAL_COLORS(0);i++)
  76.         COLOR(0,i) = (*(color_prom++) & 0x0f) + 0x10;
  77. }
  78.  
  79. WRITE_HANDLER( megazone_flipscreen_w )
  80. {
  81.     if (flipscreen != (data & 1))
  82.     {
  83.         flipscreen = data & 1;
  84.         memset(dirtybuffer,1,videoram_size);
  85.     }
  86. }
  87.  
  88. int megazone_vh_start(void)
  89. {
  90.     dirtybuffer = 0;
  91.     tmpbitmap = 0;
  92.  
  93.     if ((dirtybuffer = malloc(videoram_size)) == 0)
  94.         return 1;
  95.     memset(dirtybuffer,1,videoram_size);
  96.  
  97.     if ((tmpbitmap = osd_new_bitmap(256,256,Machine->scrbitmap->depth)) == 0)
  98.     {
  99.         free(dirtybuffer);
  100.         return 1;
  101.     }
  102.  
  103.     return 0;
  104. }
  105.  
  106. void megazone_vh_stop(void)
  107. {
  108.     free(dirtybuffer);
  109.     osd_free_bitmap(tmpbitmap);
  110.  
  111.     dirtybuffer = 0;
  112.     tmpbitmap = 0;
  113. }
  114.  
  115.  
  116. /***************************************************************************
  117.  
  118.   Draw the game screen in the given osd_bitmap.
  119.   Do NOT call osd_update_display() from this function, it will be called by
  120.   the main emulation engine.
  121.  
  122. ***************************************************************************/
  123. void megazone_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  124. {
  125.     int offs;
  126.     int x,y;
  127.  
  128.     /* for every character in the Video RAM, check if it has been modified */
  129.     /* since last time and update it accordingly. */
  130.     for (offs = videoram_size - 1;offs >= 0;offs--)
  131.     {
  132.         if (dirtybuffer[offs])
  133.         {
  134.             int sx,sy,flipx,flipy;
  135.  
  136.             dirtybuffer[offs] = 0;
  137.  
  138.             sx = offs % 32;
  139.             sy = offs / 32;
  140.             flipx = colorram[offs] & (1<<6);
  141.             flipy = colorram[offs] & (1<<5);
  142. //            if (flipscreen)
  143. //            {
  144. //                sx = 31 - sx;
  145. //                sy = 31 - sy;
  146. //                flipx = !flipx;
  147. //                flipy = !flipy;
  148. //            }
  149.  
  150.             drawgfx(tmpbitmap,Machine->gfx[0],
  151.                     ((int)videoram[offs]) + ((colorram[offs] & (1<<7) ? 256 : 0) ),
  152.                     (colorram[offs] & 0x0f) + 0x10,
  153.                     flipx,flipy,
  154.                     8*sx,8*sy,
  155.                     0,TRANSPARENCY_NONE,0);
  156.         }
  157.     }
  158.  
  159.     /* copy the temporary bitmap to the screen */
  160.     {
  161.         int scrollx = -*megazone_scrolly + 4*8;
  162.         int scrolly = -*megazone_scrollx;
  163.  
  164.         copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  165.     }
  166.  
  167.     /* Draw the sprites. */
  168.     {
  169.         for (offs = spriteram_size-4; offs >= 0;offs -= 4)
  170.         {
  171.             int sx,sy,flipx,flipy;
  172.  
  173.  
  174.             sx = spriteram[offs + 3] + 4*8;
  175.             sy = 255-((spriteram[offs + 1]+16)&0xff);
  176.  
  177.             flipx = ~spriteram[offs+0] & 0x40;
  178.             flipy = spriteram[offs+0] & 0x80;
  179.  
  180. //            if (flipscreen)
  181. //            {
  182. //                sx = 240 - sx;
  183. //                sy = 240 - sy;
  184. //                flipx = !flipx;
  185. //                flipy = !flipy;
  186. //            }
  187.             drawgfx(bitmap,Machine->gfx[1],
  188.                     spriteram[offs + 2],
  189.                     spriteram[offs + 0] & 0x0f,
  190.                     flipx,flipy,
  191.                     sx,sy,
  192.                     &Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  193.         }
  194.     }
  195.  
  196.     for (y = 0; y < 32;y++)
  197.     {
  198.         offs = y*32;
  199.         for (x = 0; x < 6; x++)
  200.         {
  201.             int sx,sy,flipx,flipy;
  202.  
  203.             sx = x;
  204.             sy = y;
  205.  
  206.             flipx = megazone_colorram2[offs] & (1<<6);
  207.             flipy = megazone_colorram2[offs] & (1<<5);
  208.             drawgfx(bitmap,Machine->gfx[0],
  209.                     ((int)megazone_videoram2[offs]) + ((megazone_colorram2[offs] & (1<<7) ? 256 : 0) ),
  210.                     (megazone_colorram2[offs] & 0x0f) + 0x10,
  211.                     flipx,flipy,
  212.                     8*sx,8*sy,
  213.                     0,TRANSPARENCY_NONE,0);
  214.             offs++;
  215.         }
  216.     }
  217. }
  218.